<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.name" placeholder="寻主信息名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="selectsearchMasterMsg">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="searchMasterMsg" highlight-current-row v-loading="listLoading"
              @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" label="序号" width="60">
      </el-table-column>
      <el-table-column prop="title" label="寻主信息标题" width="150">
      </el-table-column>
      <el-table-column prop="name" label="宠物名字" width="200">
      </el-table-column>
      <el-table-column prop="age" label="年龄" width="100">
      </el-table-column>
      <el-table-column prop="address" label="寻主信息地址" width="250">
      </el-table-column>
      <el-table-column prop="pet_type" label="宠物类型" width="100">
      </el-table-column>
      <el-table-column prop="gender" label="性别" width="80" sortable>
        <template scope="scope">
          <span v-if="scope.row.gender==0" style="color: hotpink">母</span>
          <span v-if="scope.row.gender==1" style="color: blue">公</span>
        </template>
      </el-table-column>
      <el-table-column prop="price" label="价格" width="150" e>
      </el-table-column>
      <el-table-column prop="note" label="审核信息" width="250" e>
      </el-table-column>
      <el-table-column label="操作" width="250">
        <template scope="scope">
          <el-button type="warning" :disabled="scope.row.state!==0" size="small"
                     @click="handleAudit(scope.$index, scope.row)">寻主信息审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination layout="prev, pager, next"
                     @current-change="handleCurrentChange"
                     :page-size="pageSize"
                     :total="totals"
                     :current-page="currentPage"
                     style="float:right;">
      </el-pagination>
    </el-col>
    <!-- 审核模态框 -->
    <el-dialog title="审核寻主信息" :visible.sync="shopAuditVisible" :close-on-click-modal="false">
      <el-form :model="shopAuditLog" label-width="80px" ref="shopAuditLogForm">
        <el-form-item label="备注" prop="note">
          <el-input type="textarea" v-model="shopAuditLog.note"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="shopAuditVisible = false">取消</el-button>
        <el-button type="primary" @click.native="auditPass">通过</el-button>
        <el-button type="primary" @click.native="auditReject">驳回</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import util from '../../common/js/util'
//import NProgress from 'nprogress'
import {getUserListPage, removeUser, batchRemoveUser, editUser, addUser} from '../../api/api';

export default {
  data() {
    return {
      filters: {
        name: ''
      },
      emps: [],
      searchMasterMsg: [],
      options: [],
      totals: 0,
      currentPage: 1,
      pageSize: 5,
      title: '',
      listLoading: false,
      sels: [],//列表选中列

      saveFormVisible: false,//编辑界面是否显示
      saveLoading: false,
      saveFormRules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ]
      },
      //编辑界面数据
      saveForm: {
        name: '',
        tel: '',
        state: '',
        address: '',
        logo: '',
        adminId: '',
      },
      fileList: [],
      //审核模态框
      shopAuditVisible: false,
      //编辑界面数据
      shopAuditLog: {
        shopId: null,
        note: ''
      },
    }
  },
  methods: {
    handlePreview(file) {
      console.log(file);
    },
    //点击寻主信息审核弹出模态框
    handleAudit: function (index, row) {
      this.shopAuditLog.shopId = row.id;
      this.shopAuditVisible = true;
    },
//审核驳回
    auditReject() {
      this.$http.post("searchMasterMsg/audit/reject", this.shopAuditLog).then(res => {
        if (res.data.success) {
          this.$message({
            message: '驳回成功',
            type: 'success'
          });
        } else {
          this.$message({
            message: '驳回失败',
            type: 'error'
          });
        }
        this.shopAuditVisible = false;
        this.getSearchMasterMsgToAudit();
      })
    },
    //审核通过
    auditPass() {
      this.$http.post("searchMasterMsg/audit/pass", this.shopAuditLog).then(result => {
        result = result.data;
        if (result.success) {
          this.$message({
            message: '审核通过',
            type: 'success'
          });
        } else {
          this.$message({
            message: '审核失败',
            type: 'error'
          });
        }
        this.shopAuditVisible = false;
        this.getSearchMasterMsgToAudit();
      })
    },
    selectsearchMasterMsg() {
      this.currentPage = 1;
      this.getSearchMasterMsgToAudit();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getSearchMasterMsgToAudit();
    },
    //获取寻主信息列表
    getSearchMasterMsgToAudit() {
      let para = {
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        keyword: this.filters.name
      };
      this.listLoading = true;
      this.$http.post("searchMasterMsg/pageList", para).then((res) => {
          this.searchMasterMsg = res.data.data;
          this.totals = res.data.totals;
          this.listLoading = false;
      }).catch((res => {
        this.$message.error("网络繁忙");
      }));
    },


    selsChange: function (sels) {
      this.sels = sels;
    },
  },
  mounted() {
    this.getSearchMasterMsgToAudit();
  }
}

</script>

<style scoped>

</style>